//
//  VisitorViewController.swift
//  XKWeibo
//
//  Created by 小k on 15/11/4.
//  Copyright © 2015年 小k. All rights reserved.
//

import UIKit

class VisitorViewController: UITableViewController {

//    private var userLongin = false
    // 用户登录标记
    private var userLongin = XKUserAccountViewModel.sharedUserAccount.userLogin
    // 定义一个属性记录是否创建访客视图
    var visitorView:XKVisitorView?
    
    override func loadView() {
        // 根据用户登录情况 判断是否创建
        userLongin ? super.loadView(): userVisitorView()
        
    }
    
    
    // 创建访客视图界面
    private func userVisitorView () {
        // 替换视图
        visitorView = XKVisitorView()
//        view.backgroundColor = UIColor.redColor()
//        visitorView?.delegate = self
        view = visitorView
        
        // 添加给按钮添加监听方法
        visitorView?.registerBtn.addTarget(self, action: "visitorViewRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.longinBtn.addTarget(self, action: "visitorViewLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        // 设置导航控制器按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorViewLogin")
    }
}

// MARK: - 访客视图按钮的监听方法
extension VisitorViewController{//: XKVisitorViewDelegate {
@objc private func visitorViewRegister () {
    print("注册")
}

@objc private func visitorViewLogin () {
    // 创建控制器
    let vc = OAuthViewController()

    
    let nav = UINavigationController(rootViewController: vc)
    
    presentViewController(nav, animated: true, completion: nil)

    
}
    
}